﻿$(function () {
    var eventId = querySt('id');
    ajaxCall('../DataService.asmx/GetSessionsForEvent', false, "{'eventId':'" + eventId + "'}",
                function (msg) {
                    if (msg.d == null) {
                        $('#sessionsDiv').html("There are still no sessions in the database for this event");
                    } else {
                        for (var i in msg.d) {
                            var speakers = msg.d[i].Speakers[0].FirstName + " " + msg.d[i].Speakers[0].LastName;
                            for (var j = 1; j < msg.d[i].Speakers.length; j++) {
                                speakers = speakers + ", " + msg.d[i].Speakers[j].FirstName + " " + msg.d[i].Speakers[j].LastName;
                            }
                            var sessions = [
                                { ID: msg.d[i].ID, Title: msg.d[i].Title, Description: msg.d[i].Description, Language: msg.d[i].Language, Speakers: speakers }
                            ];
                            $('#SessionTemplate').tmpl(sessions).appendTo('#sessionsDiv');
                        }
                    }
                },
                function () {
                    alert("Error hapend while reading from database");
                }
            );

    ajaxCall('../DataService.asmx/GetSpeakersForEvent', false, "{'eventId':'" + eventId + "'}",
        function (msg) {
            if (msg.d == null) {
                $('#speakersDiv').html("No speakers found in the database");
            }
            else {
                for (i in msg.d) {
                    var speakers = [
                        { ID: msg.d[i].ID, FirstName: msg.d[i].FirstName, LastName: msg.d[i].LastName, CompanyName: msg.d[i].CompanyName, Country: msg.d[i].Country, ExpertIn: msg.d[i].ExpertIN, Link: msg.d[i].Link, Description: msg.d[i].Description }
                    ];

                    $('#SpeakerTemplate').tmpl(speakers).appendTo('#speakersDiv ');
                }
            }
        },
        function () {
            alert("Error happend while reading data from database");
        }
    );

    $('.btnSessionDescription').click(function () {
        if ($(this).parent('.sessionDetailsHistory').children('.sessionDescriptionHistory').is(':hidden')) {
            $(this).parent('.sessionDetailsHistory').children('.sessionDescriptionHistory').show("slide", { direction: "down" }, 1000);
            $(this).parent('.sessionDetailsHistory').children('.sessionDescriptionHistory').css('visibility', 'visible');
            $(this).html('Hide description');
        }
        else {
            $(this).parent('.sessionDetailsHistory').children('.sessionDescriptionHistory').hide("slide", { direction: "down" }, 1000);
            $(this).parent('.sessionDetailsHistory').children('.sessionDescriptionHistory').css('visibility', 'hidden');
            $(this).html('Show description');
        }
    });

    $('.ShDisc').click(function () {
        if ($(this).parent('.speakerDataHistory').children('.descrDivHistory').is(':hidden')) {
            $(this).parent('.speakerDataHistory').children('.descrDivHistory').show("slide", { direction: "left" }, 1000);
            $(this).parent('.speakerDataHistory').children('.descrDivHistory').css('visibility', 'visible');
            $(this).html('Hide Details');
        }
        else {
            $(this).parent('.speakerDataHistory').children('.descrDivHistory').hide("slide", { direction: "left" }, 1000);
            $(this).parent('.speakerDataHistory').children('.descrDivHistory').css('visibility', 'hidden');
            $(this).html('Show Details');
        }

    });

});

           